package flexexamples.domain
{
	import flexexamples.repository.ProjectRepository;
	
	import mx.collections.ArrayCollection;
	
	[Bindable]
	[RemoteClass(alias="flexexamples.domain.Project")]
	public class Project
	{
		public var repository:ProjectRepository;
		public var resultHandlerSave:Function;
				
		public var id:int;
		public var name:String;
		
		[ArrayElementType("flexexamples.domain.Iteration")]
		public var iterations:ArrayCollection = new ArrayCollection();
		
		[ArrayElementType("flexexamples.domain.UserStory")]
		public var backlog:ArrayCollection;
		
		/* Contructor */
		public function Project()
		{
			backlog = new ArrayCollection()
			addIteration(new Iteration());			
		}
		
		public function addIteration(iteration:Iteration) : void
		{
			iteration.project = this;
			iterations.addItem(iteration);
		}
		
		public function addUserStory(story:UserStory) : void
		{
			backlog.addItem(story);
		}
		
		public function save() : void
		{
			repository.saveProject(this, resultHandlerSave);
		}
	}
}